/* ppptiqd.p - ITEM COST INQUIRY SUBPROGRAM                             */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Id:: ppptiqd.p 2366 2010-11-10 01:47:19Z zzh                           $: */
/* MODIFIED FROM PPPTMTD.P                                              */
/* REVISION: 7.3      LAST MODIFIED: 02/05/93   BY: pma *G032*          */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/*           7.3                     09/03/94   BY: bcm *GL93*          */
/*           7.3                     11/01/94   BY: ame *GN83*          */
/*           7.3                     03/24/95   BY: aed *G0J8*          */
/*           7.3                     04/03/95   BY: aed *G0FB*          */
/*           7.3                     07/13/95   BY: jzs *G0S6*          */
/*           8.6                     10/09/97   BY: mzv *K0PK*          */
/*           8.7                     05/27/98   BY: *K1QV* A. Shobha    */
/*           8.7                     10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 07/20/00   BY: *N0GF* Mudit Mehta      */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KQ* myb              */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.10.1.5  BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00K*      */
/* Revision: 1.10.1.6  BY: Katie Hilbert      DATE: 10/16/03 ECO: *Q04B*      */
/* Revision: 1.10.1.7  BY: Vandna Rohira      DATE: 02/14/05 ECO: *P35T*      */
/* Revision: 1.10.1.8  BY: Rafiq S            DATE: 11/25/05 ECO: *Q0N0*      */
/* $Revision: 1.10.1.9 $   BY: Zhijun Guan    DATE: 11/09/11 ECO: *R1V9*      */
/*-Revision end---------------------------------------------------------------*/
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{us/bbi/mfdeclre.i}
{us/bbi/gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter sct_recid as recid.
define input parameter frtitle   as character format "x(24)".

define new shared variable global_costsim  like sc_sim.
define new shared variable global_category like sc_category.
define new shared variable global_element  like sc_element.
define     shared variable csset           like cs_set initial "".
define     shared variable site            like si_site initial "".

define variable i       as integer no-undo.
define variable usr_val as character format "x(12)" extent 5.
define variable usr_elm like sc_element extent 5.
define shared frame d.
define shared frame d1.
define shared frame d0.

define shared workfile sptwkfl
   field element  like spt_element column-label "Element"
   field primary  like mfc_logical column-label "Pri"
   field prim2    like mfc_logical
   field ao       like spt_ao      column-label "A/O"
   field cst_tl   like spt_cst_tl  column-label "This Level"
   field cst_ll   like spt_cst_ll  column-label "Lower Level"
   field cst_tot  like spt_cst_tl  column-label "Total"
   field cat_desc as character     column-label "Category"
   field seq      like spt_pct_ll
   field part     like pt_part.
define variable c_fiscal_desc as character format "x(40)" no-undo.

form
   {us/pp/ppptmta5.i}
with frame d1 title color normal
   (getFrameTitle("ITEM_PRICE_DATA",23))
   side-labels width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame d1:handle).

form
   {us/pp/ppptmta9.i}
with frame d ? down title color normal
   (getFrameTitle(frtitle,9))
   width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame d:handle).

/* FOR BOOLEAN VALUE IN DOWN FRAME,    */
/* ENSURE TRANSLATION TO USER LANGUAGE */


/* This users of frame d0 does not need to overlay at startrow */
form
   {us/pp/ppptmta9.i}
with frame d0 1 down width 80 no-labels
   title color normal (getFrameTitle("TOTALS",16)).

for each lngd_det no-lock
   where lngd_dataset = "sc_mstr"
     and lngd_key1 = ""
     and lngd_key2 = ""
     and lngd_key3 = ""
     and lngd_field = "sc_category"
     and lngd_lang = global_user_lang:
   if lngd_key4 = "1" then usr_val[1] = lngd_translation.
   usr_val[integer(lngd_key4)] = lngd_translation.
   usr_elm[integer(lngd_key4)] = substring(lngd_translation,1,8).
end.

find sct_det where recid(sct_det) = sct_recid no-lock.
global_costsim = csset.

for each sptwkfl exclusive-lock:
   delete sptwkfl.
end.

i = 0.
for each spt_det no-lock
   where spt_domain = global_domain
     and spt_site   = sct_site
     and spt_sim    = sct_sim
     and spt_part   = sct_part
by spt_pct_ll by spt_cst_tl descending by spt_element:
   i = i + 1.
   create sptwkfl.
   assign
      element = spt_element
      primary = no
      prim2   = no
      ao      = spt_ao
      cst_tl  = spt_cst_tl
      cst_ll  = spt_cst_ll
      cst_tot = spt_cst_tl + spt_cst_ll
      part    = sct_part
      seq     = i.
   if spt_pct_ll = truncate(spt_pct_ll,0) then
      assign
         primary = yes
         prim2   = yes.
   cat_desc = usr_val[integer(truncate(spt_pct_ll,0))].
   release spt_det.
end.

find first sptwkfl no-error.
if not available sptwkfl then do i = 1 to 5:
   create sptwkfl.
   assign
      element  = usr_elm[i]
      primary  = yes
      prim2    = yes
      ao       = no
      cst_tl   = 0
      cst_ll   = 0
      cst_tot  = 0
      part     = sct_part
      seq      = i
      cat_desc = usr_val[i].
end.

for each sptwkfl break by part:
   accumulate cst_tl (total by part).
   accumulate cst_ll (total by part).
   accumulate cst_tot (total by part).
end.

display
   getTermLabel("TOTALS",7) + ":" @ element
   (accum total cst_tl)           @ cst_tl
   (accum total cst_ll)           @ cst_ll
   (accum total cst_tot)          @ cst_tot
   sct_cst_date                   @ cat_desc
with frame d0.

for each sptwkfl by seq with frame d:
   display
      element
      cst_tl
      primary
      cst_ll
      cst_tot
      ao
      cat_desc.
   down.
end.
